/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package dominio;

import java.io.Serializable;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 *
 * @author gilcemar e naliane
 */
@Entity
@Table(name = "consorcio", catalog = "traxx", schema = "public")
@NamedQueries({
    @NamedQuery(name = "Consorcio.findAll", query = "SELECT c FROM Consorcio c"),
    @NamedQuery(name = "Consorcio.findByCpf", query = "SELECT c FROM Consorcio c WHERE c.cpf = :cpf"),
    @NamedQuery(name = "Consorcio.findByPlano", query = "SELECT c FROM Consorcio c WHERE c.plano = :plano"),
    @NamedQuery(name = "Consorcio.findByModelo", query = "SELECT c FROM Consorcio c WHERE c.modelo = :modelo"),
    @NamedQuery(name = "Consorcio.findByValor", query = "SELECT c FROM Consorcio c WHERE c.valor = :valor"),
    @NamedQuery(name = "Consorcio.findByDatainicio", query = "SELECT c FROM Consorcio c WHERE c.datainicio = :datainicio"),
    @NamedQuery(name = "Consorcio.findMelhoresLocaisDeVenda",query = "Select e.bairro,count(e.bairro) from Endereco e, Cliente c, Consorcio cons where e.cpf = c.cpf and c.cpf = cons.cpf group by e.bairro;")})
public class Consorcio implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @Column(name = "cpf", nullable = false, length = 14)
    private String cpf;
    @Basic(optional = false)
    @Column(name = "plano", nullable = false)
    private int plano;
    @Basic(optional = false)
    @Column(name = "modelo", nullable = false, length = 20)
    private String modelo;
    @Basic(optional = false)
    @Column(name = "valor", nullable = false)
    private float valor;
    @Basic(optional = false)
    @Column(name = "datainicio", nullable = false)
    @Temporal(TemporalType.DATE)
    private Date datainicio;
    @JoinColumn(name = "cpf", referencedColumnName = "cpf", nullable = false, insertable = false, updatable = false)
    @OneToOne(optional = false)
    private Cliente cliente;

    public Consorcio() {
    }

    public Consorcio(String cpf) {
        this.cpf = cpf;
    }

    public Consorcio(String cpf, int plano, String modelo, float valor, Date datainicio) {
        this.cpf = cpf;
        this.plano = plano;
        this.modelo = modelo;
        this.valor = valor;
        this.datainicio = datainicio;
    }

    public String getCpf() {
        return cpf;
    }

    public void setCpf(String cpf) {
        this.cpf = cpf;
    }

    public int getPlano() {
        return plano;
    }

    public void setPlano(int plano) {
        this.plano = plano;
    }

    public String getModelo() {
        return modelo;
    }

    public void setModelo(String modelo) {
        this.modelo = modelo;
    }

    public float getValor() {
        return valor;
    }

    public void setValor(float valor) {
        this.valor = valor;
    }

    public Date getDatainicio() {
        return datainicio;
    }

    public void setDatainicio(Date datainicio) {
        this.datainicio = datainicio;
    }

    public Cliente getCliente() {
        return cliente;
    }

    public void setCliente(Cliente cliente) {
        this.cliente = cliente;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (cpf != null ? cpf.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Consorcio)) {
            return false;
        }
        Consorcio other = (Consorcio) object;
        if ((this.cpf == null && other.cpf != null) || (this.cpf != null && !this.cpf.equals(other.cpf))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "dominio.Consorcio[cpf=" + cpf + "]";
    }

}
